import json
import os

from optparse import OptionParser
from pymongo import MongoClient

client = MongoClient('localhost', 27017, connect = False)

qushu_resume_db = client['qushu_resume_db']
qushu_resume_coll = qushu_resume_db['qushu_resume_coll']

parser = OptionParser(usage = "%prog [options]")

parser.add_option("-f", "--filename", action = "store_true", dest = "filename", default = False, help = "file path")

options, args = parser.parse_args()

if options.filename and os.path.exists(options.filename):
    with open(options.filename, 'r') as file:
        data = json.load(file)

        n = 0
        total = len(data)

        for item in data:
            n += 1

            percent = float(n) * 100 / float(total)
            sys.stdout.write("%.2f" % percent);
            sys.stdout.write("\r");
            sys.stdout.flush()

            qushu_resume_coll.insert_one(item)
